<template>
  <!--模态窗 多行-->
  <transition
    name="custom-classes-transition"
    enter-active-class="animated fadeInDown"
    leave-active-class="animated fadeOutUp"
  >
    <div class="modal-ctrl-body" v-show="RevampModalObj.isShow">
      <div class="modal-ctrl-main even-row-ctrl">

        <div class="modal-title">
          <p v-text="isDetailsModal ? '查询重点人信息详情':'修改重点人信息'"></p>
        </div>

        <div class="modal-ctrl-content">
          <div class="even-row">

          <!--  <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                录入模式：
              </div>
              <select @change="sexUpTypeSelect" :value="AddModalData.upType">
                <option value="-1">请选择录入模式</option>
                <option value="1">一般录入</option>
                <option value="2">特殊录入</option>
              </select>
              <span class="modal-help" @mouseenter="upDataTypeTextIsShowFn" @mouseleave="upDataTypeTextIsShowFn">
                什么是录入模式？
              </span>
              <transition
                name="bounce"
              >
                <div class="text-body" v-show="upDataTypeTextIsShow">
                  录入模式分为两种：<br>
                  1:一般录入：正常录入模式与验证规则。<br>
                  2:特殊录入：只用录入重点人照片与备注，其他信息选填。
                </div>
              </transition>
            </div>

            <div class="clear-float"></div>-->

            <div class="modal-row photo" style="display: block;height :auto;">
              <div class="modal-form-key f-l">
                人像照片：
              </div>
              <div class="photo-up-btn f-l" v-show="!isDetailsModal">
                <input type="file" name="photo" ref="formFile" @change="filePhoto" class="modal-text f-l">
                <span class="photo-btn">选择相片</span>
               <!-- v-if="AddModalData.importPerson.importPersonImages[0]" -->
                <input type="hidden" name="photoId" v-model="AddModalData.importPerson.importPersonImages[0].url">
              </div>

              <button type="button" class="btn btn-info f-l" :disabled="upImgBtn" v-if="!isDetailsModal" @click="bindPhoto" v-show="photoSrc!==''">上传照片</button>
              <button type="button" class="btn btn-info f-l" @click="clearBindPhoto" v-if="!isDetailsModal" v-show="photoSrc!==''">清除</button>

              <img :src="photoSrc" class="f-l photo-img" alt="">
            </div>
         <!--   <div class="clear-float"></div>
            <div class="modal-row" v-show="AddModalData.upType === '2'">
              <div class="modal-form-key f-l indispensable">
                备注：
              </div>
              <input type="text" v-model="AddModalData.name" class="modal-text f-l">
            </div>-->

            <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                姓名：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPerson.name" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l indispensable">
                性别：
              </div>
              <select @change="sexSelect" :disabled="isDetailsModal" :value="AddModalData.importPerson.sex">
                <option value="-1">请选择</option>
                <option value="男">男</option>
                <option value="女">女</option>
              </select>
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l indispensable">
                身份证号码：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPerson.idCardNo" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l">
                手机号码：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPerson.mobile" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l">
                Mac码：
              </div>
              <input type="text"
                     :readonly="isDetailsModal"
                     v-for=" item in AddModalData.importPerson.importSocials "
                     v-model="item.socialAccount" class="modal-text f-l"
                     maxlength="50"
              >
            <!--  <input type="text" v-model="AddModalData.importPerson.importSocials.socialAccount" class="modal-text f-l">-->
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l">
                户籍所在地：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPerson.birthPlace" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                出生日期：
              </div>
              <div class="input-group date" id="revampKeyPersonDate">
                <span class="input-group-addon glyphicon glyphicon-list"><i class="fa fa-calendar"></i></span>
                <input type="hidden" :readonly="isDetailsModal" ref="revampBirthday"  name="birthday">
                <input type="text" :disabled="isDetailsModal" readonly="readonly" ref="revampBirthday" id="datetimepicker" class="form-control" data-date-format="dd-mm-yyyy">
              </div>
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                民族：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.nation" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l ">
                姓名拼音：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.spellName" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l ">
                现住址：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.currentAddress" class="modal-text f-l" maxlength="200">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l ">
                所属群体：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPerson.ownerGroup" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l ">
                人员等级：
              </div>
              <select @change="selectPersonLevel" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.personLevel">
                <option value="-1">请选择</option>
                <option value="1">一级</option>
                <option value="2">二级</option>
                <option value="3">三级</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l ">
                人员状态：
              </div>
              <select @change="selectPersonnelStatus" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.personnelStatus">
                <option value="-1">请选择</option>
                <option value="1">已处置</option>
                <option value="2">处置中</option>
                <option value="3">未处置</option>
              </select>
            </div>

            <!-- 以下为选填字段 -->
            <div class="modal-row">
              <div class="modal-form-key f-l">
                重点人类型：
              </div>

              <input type="text" :disabled="isDetailsModal" v-model="AddModalData.importPerson.importPersonTypes[0].typename" @click="getKeyPersonClassTreeIsShow" readonly="readonly" class="modal-text f-l" >
              <input type="hidden" :disabled="isDetailsModal" v-model="AddModalData.importPerson.importPersonTypes[0].id">
              <!--{{sectionTreeIShow}}-->
              <div class="sectionTree" v-show="keyPersonClassTreeIShow">
                <div id="RevampKeyPersonClassTree" class="ztree sectionTree-box"></div>
              </div>
              <!--<input type="text" v-for="item in AddModalData.importPerson.importPersonTypes" v-model="item" class="modal-text f-l">-->
            </div>
            <div class="modal-row">
              <div class="modal-form-key f-l">
                行驶证号码：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.drivingLicenseNumber" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                文化程度：
              </div>
             <!-- <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.educationalLevel" class="modal-text f-l" maxlength="50">-->
              <select @change="educationLevel" :value="AddModalData.importPersonInfo.educationalLevel">
                <option value="">请选择</option>
                <option value="文盲或半文盲">文盲或半文盲</option>
                <option value="小学">小学</option>
                <option value="初中">初中</option>
                <option value="高中">高中</option>
                <option value="技工学校">技工学校</option>
                <option value="中等专业学校">中等专业学校</option>
                <option value="大学专科">大学专科</option>
                <option value="大学本科">大学本科</option>
                <option value="硕士">硕士</option>
                <option value="博士及以上">博士及以上</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                港澳通行证：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.exitPermit" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                曾用名：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.formerName" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                婚姻状况：
              </div>
             <!-- <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.maritalStatus" class="modal-text f-l" maxlength="30">-->
              <select @change="selectMaritalStatus" :value="AddModalData.importPersonInfo.maritalStatus">
                <option value="">请选择</option>
                <option value="未婚">未婚</option>
                <option value="已婚">已婚</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                籍贯：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.nativePlace" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                绰号：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.nickname" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                护照号：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.passportNumber" class="modal-text f-l" maxlength="50">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                详细地址：
              </div>
              <input type="text" :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.streetAddress" class="modal-text f-l" maxlength="200">
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                是否为武汉户籍：
              </div>
              <select @change="isWuhanIdcardSelect" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.isWuhanIdcard">
                <option value="-1">请选择</option>
                <option value="0">否</option>
                <option value="1">是</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                是否常住人口：
              </div>
              <select @change="selectPermanentPopulation" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.permanentPopulation">
                <option value="false">否</option>
                <option value="true">是</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                是否暂住人口：
              </div>
              <select @change="selectTemporaryPopulation" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.temporaryPopulation">
                <option value="false">否</option>
                <option value="true">是</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                车牌号：
              </div>
              <input type="text" :readonly="isDetailsModal" v-for=" item in AddModalData.importPerson.importVechiles " v-model="item.vechileNo" class="modal-text f-l" maxlength="50">
             <!-- <input type="text" v-model="AddModalData.importPerson.importVechiles.vechileNo" class="modal-text f-l">-->
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                是否有犯罪记录：
              </div>
              <select @change="selectIsCriminalRecord" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.isCriminalRecord">
                <option value="-1">请选择</option>
                <option value="0">否</option>
                <option value="1">是</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                是否有吸毒史：
              </div>
              <select @change="selectIsDrugUse" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.isDrugUse">
                <option value="-1">请选择</option>
                <option value="0">否</option>
                <option value="1">是</option>
              </select>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                是否有暴力倾向：
              </div>
              <select @change="selectIsViolent" :disabled="isDetailsModal" :value="AddModalData.importPersonInfo.isViolent">
                <option value="-1">请选择</option>
                <option value="0">否</option>
                <option value="1">是</option>
              </select>
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l">
                所属分局：
              </div>
              <input type="text"
                     :disabled="isDetailsModal"
                     v-model="sectionTreeName"
                     readonly="readonly"
                     @click="getStationTree('sectionTree')"
                     class="modal-text f-l" >
              <input type="hidden"
                     :disabled="isDetailsModal"
                     v-model="AddModalData.importPersonInfo.secondpolicestationid">
              <!--{{sectionTreeIShow}}-->
              <div class="sectionTree" v-show="sectionTreeIShow">
                <div id="RevampSectionTree" class="ztree sectionTree-box"></div>
              </div>
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l">
                所属派出所：
              </div>
              <input type="text" :disabled="isDetailsModal" v-model="sectionPoliceTreeName" readonly="readonly" @click="getStationTree('sectionPolice')" class="modal-text f-l" >
              <input type="hidden" :disabled="isDetailsModal" v-model="AddModalData.importPersonInfo.policestationid">
              <!--{{sectionTreeIShow}}-->
              <div class="sectionTree" v-show="sectionPoliceTreeIShow">
                <div id="RevampSectionPoliceTree" class="ztree sectionTree-box"></div>
              </div>
            </div>

            <div class="modal-row" >
              <div class="modal-form-key f-l">
                上报单位：
              </div>
              <input type="text" :disabled="isDetailsModal" v-model="sectionDataTreeName" readonly="readonly" @click="getStationTree('sectionData')" class="modal-text f-l" >
                 <input type="hidden" :disabled="isDetailsModal" v-model="AddModalData.importPerson.reportunit">
              <!--{{sectionTreeIShow}}-->
              <div class="sectionTree" v-show="sectionDataTreeIShow">
                <div id="RevampSectionDataTree" class="ztree sectionTree-box"></div>
              </div>
            </div>

            <div class="modal-row">
              <div class="modal-form-key f-l">
                犯罪记录简述：
              </div>
              <!--<input type="text" class="modal-text f-l">-->
              <textarea :readonly="isDetailsModal" v-model="AddModalData.importPersonInfo.criminalRecordDescribe" maxlength="200"></textarea>
            </div>
            <input type="hidden" v-model="AddModalData.importPerson.stationid"/>
          </div>

        </div>
        <div class="btns text-r">
          <button type="button" class="btn btn-default" @click="close" v-text="isDetailsModal ? '关闭':'取消'"></button>
          <button type="button" class="btn btn-info" v-if="!isDetailsModal" v-show="permissions" @click="subBtn">确定</button>
        </div>
        <!--{{userDetailsModal.obj}}-->
      </div>
    </div>
  </transition>
</template>

<script>
    export default {
        name: "AddkeyPersonListModal",
        props:["RevampModalObj","selectRowId","permissions","isDetailsModal"],
        data(){
          return{
            AddModalData:{
              "importPerson": {
                "id":null,
                "birthPlace": "", //birthPlace
                "idCardNo": "", //身份证号码
                "reportunit": "",//上报单位
                "importPersonImages": [ //相片
                  {
                    "url": ""
                  }
                ],
                "importPersonTypes": [ //重点人类型
                  {
                    "id": "",
                    "typename": ""
                  }
                ],
                "importSocials": [
                  {
                    "socialAccount": "",//mac地址
                    "type": "mac",
                  }
                ],
                "importVechiles": [
                  {
                    "vechileNo": "",//车牌号
                  }
                ],
                "mobile": "", //手机号
                "name": "", //姓名
                "ownerGroup": "", //所属群体
                "sex": "-1",//性别
                "stationid": "" //管辖所属单位 老字段
              },
              "importPersonInfo": {
                "birthday": "",//出生日期
                "criminalRecordDescribe": "",//犯罪记录简述
                "currentAddress": "",//现住址
                "drivingLicenseNumber": "", //行驶证号码
                "educationalLevel": "",//文化程度
                "exitPermit": "",//港澳通行证
                "formerName": "",//曾用名
                "isCriminalRecord": "-1",//是否有犯罪记录
                "isDrugUse": "-1",//是否有吸毒史
                "isViolent": "-1",//是否有暴力倾向
                "isWuhanIdcard": "-1", //isWuhanIdcard
                "maritalStatus": "",//婚姻情况
                "nation": "",//民族
                "nativePlace": "",//籍贯
                "nickname": "",//绰号
                "passportNumber": "",//护照号
                "permanentPopulation": "false", //常住人口
                "personLevel": "-1",//人员等级
                "personnelStatus": "-1",//人员状态
                "policestationid": "",//管辖派出所
                "secondpolicestationid": "",//管辖分局
                "spellName": "",//姓名拼音
                "streetAddress": "",//详细住址
                "temporaryPopulation": "false", //暂住人口
                "sex": "",//性别
                "name": "", //姓名
                "idCardNo": "", //身份证号码
              }
            },
            photoSrc:"",
            photoFile:"",
            upDataTypeTextIsShow:false,
            carTypeList:[],
            sectionTreeName:'',
            sectionPoliceTreeName:'',
            sectionDataTreeName:'',
            ketPersonClassTreeName:'',
            upImgBtn: true,
            sectionTree:[],
            sectionTreeSetting : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            sectionPoliceTreeSetting : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            sectionDataTreeSetting : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            keyPersonClassTree : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            sectionTreeIShow:false,
            sectionPoliceTreeIShow:false,
            sectionDataTreeIShow:false,
            keyPersonClassTreeIShow:false,
          }
        },

        created(){
          //日期控件
          let _this = this;
          $(function () {
            //console.log($("#datetimepicker"));
            $('#revampKeyPersonDate').datetimepicker({
              language: "zh-CN",
              format: "yyyy-mm-dd",
              minView: "month",
              autoclose: true
            }).on("changeDate",function(ev){
              //console.log();
              let selectDate = ev.date.valueOf();
              let theDate = new Date().getTime(); //当前时间
              if( selectDate >= theDate ){
                _this.s_alert("选择时间不能是未来时间！");
                $(".form-control").val("");
                $(".form-control").prev().val("");
              }
            });
          });
        },
        mounted(){
          //获取部门树
          this.getStationTreeAjax();
          let _this = this;
          this.sectionTreeSetting.callback = {
            onClick:function(event,treeId,treeNode){ //新增警员部门树选择
              //console.log(treeNode);
              _this.AddModalData.importPersonInfo.secondpolicestationid = treeNode.id;
              _this.sectionTreeName = treeNode.name;
              _this.sectionTreeIShow = !_this.sectionTreeIShow;
            }
          };
          this.sectionPoliceTreeSetting.callback = {
            onClick:function(event,treeId,treeNode){ //新增警员部门树选择
              //console.log(treeNode);
              _this.AddModalData.importPersonInfo.policestationid = treeNode.id;
              _this.sectionPoliceTreeName = treeNode.name;
              _this.sectionPoliceTreeIShow = !_this.sectionPoliceTreeIShow;
            }
          };
          this.sectionDataTreeSetting.callback = {
            onClick:function(event,treeId,treeNode){ //新增警员部门树选择
              //console.log(treeNode);
              _this.AddModalData.importPerson.reportunit = treeNode.id;
              _this.sectionDataTreeName = treeNode.name;
              _this.sectionDataTreeIShow = !_this.sectionDataTreeIShow;
            }
          };
          this.keyPersonClassTree.callback = {
            onClick:function(event,treeId,treeNode){ //新增警员部门树选择
              //console.log(treeNode);
              _this.AddModalData.importPerson.importPersonTypes[0].id = treeNode.id;
              _this.AddModalData.importPerson.importPersonTypes[0].typename = treeNode.name;
              //console.log(_this.AddModalData.importPerson.importPersonTypes[0]);
              _this.keyPersonClassTreeIShow = !_this.keyPersonClassTreeIShow;
            }
          };
        },
        watch:{
          RevampModalObj:{
            handler(v1){
              if( v1.isShow ){

                //获取重点人类型树
                this.getKeyPersonClassTree();
                //
                //console.log(this.selectRowId);
                this.getKeyRevampData()
              }
            },
            deep:true,
          },
          sectionTree(v1){
            //console.log(this.sectionTree);
            //console.log(this.AddModalData.importPersonInfo.secondpolicestationid);

          }
        },
        methods:{
          //获取重点人详情
          getKeyRevampData(){
            //GET /BS/ImportPerson/{id}
            this.$axios.get(this.ControlObject+"/BS/ImportPerson/"+this.selectRowId)
              .then( res=>{
                //console.log(res.data);
                this.AddModalData = res.data;
                console.log(this.AddModalData.importPersonInfo.birthday);
                this.AddModalData.importPersonInfo.birthday = this.AddModalData.importPersonInfo.birthday ? this.AddModalData.importPersonInfo.birthday.split("T")[0] : "";
                if( this.AddModalData.importPerson.importPersonImages[0] && this.AddModalData.importPerson.importPersonImages[0].url ){
                  this.photoSrc = baseURL+"api/jp-TIFS-FileCenter-ms/file?businessId="+this.AddModalData.importPerson.importPersonImages[0].url;
                }else{
                  this.photoSrc = "";
                }

                //车牌
                if( this.AddModalData.importPerson.importVechiles.length === 0 ){
                  this.AddModalData.importPerson.importVechiles.push({
                    vechileNo:""
                  })
                }

                //相片
                if( this.AddModalData.importPerson.importPersonImages.length === 0 ){
                  this.AddModalData.importPerson.importPersonImages.push({
                    url:""
                  })
                }

                //重点人类型
                if( this.AddModalData.importPerson.importPersonTypes.length === 0 ){
                  this.AddModalData.importPerson.importPersonTypes.push({
                    "id": "",
                    "typename": ""
                  })
                }

                //重点人MAC
                if( this.AddModalData.importPerson.importSocials.length > 0 ){
                  let macArr = [];
                  for( let i=0;i<this.AddModalData.importPerson.importSocials.length;i++ ){
                    if( this.AddModalData.importPerson.importSocials[i].type === "mac" ){
                      macArr.push(this.AddModalData.importPerson.importSocials[i]);
                    }
                  }
                  let newImportArr = [];
                  let macPop = macArr.pop();
                  //console.log(macPop);
                  if( macPop && macPop.type === "mac" ){
                    newImportArr.push(macPop);
                    //console.log(newImportArr);
                  }else {
                    newImportArr.push({
                      "type":"mac",
                      "socialAccount":""
                    });
                  }
                  //console.log(newImportArr);
                  this.AddModalData.importPerson.importSocials = newImportArr;
                  //console.log(this.AddModalData.importPerson.importSocials);
                }else  if( this.AddModalData.importPerson.importSocials.length === 0 ){
                  this.AddModalData.importPerson.importSocials.push({
                    socialAccount:"",
                    type:""
                  })
                }

                ////console.log(this.AddModalData.importPerson.importSocials);
                this.$refs.revampBirthday.value = this.AddModalData.importPersonInfo.birthday;

                //console.log(this.sectionTree);
                for( let i=0;i<this.sectionTree.length;i++ ){
                  if( this.sectionTree[i].id === this.AddModalData.importPersonInfo.secondpolicestationid ){ //所属分局
                    //console.log(this.sectionTree[i].name);
                    this.sectionTreeName = this.sectionTree[i].name;
                  }
                  if( this.sectionTree[i].id === this.AddModalData.importPersonInfo.policestationid ){ //所属派出所
                    //console.log(this.sectionTree[i].name);
                    this.sectionPoliceTreeName = this.sectionTree[i].name;
                  }
                  if( this.sectionTree[i].id === this.AddModalData.importPerson.reportunit ){ //上报单位
                    //console.log(this.sectionTree[i].name);
                    this.sectionDataTreeName = this.sectionTree[i].name;
                  }
                }

              } )
              .catch( err=>{
                //console.log(err);
              } )
          },
          //提交
          subBtn(){

            this.AddModalData.importPersonInfo.name = this.AddModalData.importPerson.name;
            this.AddModalData.importPersonInfo.sex = this.AddModalData.importPerson.sex;
            this.AddModalData.importPersonInfo.idCardNo = this.AddModalData.importPerson.idCardNo;

            this.AddModalData.importPersonInfo.birthday = this.$refs.revampBirthday.value ? this.$refs.revampBirthday.value+"T02:09:17.245+05:30" : "";

            let regIdCode = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证正则
            let macExp =  /^[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}/; //mac地址正则

            let regexp = new RegExp(macExp);
            ////console.log(this.AddModalData.importPerson.importSocials[0]);
            ////console.log(this.AddModalData);

            if( !this.upImgBtn ){
              this.s_alert("选择相片后请点击上传按钮！");
              return false;
            }

            this.AddModalData.importPerson.name = this.JPtool.subBlank(this.AddModalData.importPerson.name);
            //return false;
            if( this.verifyForm.isNull(this.AddModalData.importPerson.name) || this.verifyForm.isName(this.AddModalData.importPerson.name) ){
              this.s_alert("姓名只能是汉字！或姓名超长！最长10个汉字！");
              // alert("姓名不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.importPerson.sex) ){
              this.s_alert("请选择性别！");
              return false;
            }
            else if( this.verifyForm.idCode(this.AddModalData.importPersonInfo.idCardNo) || this.verifyForm.isNull(this.AddModalData.importPersonInfo.idCardNo) ){
              this.s_alert("身份证为空或输入格式不正确！");
              return  false;
            }
            else if ( this.AddModalData.importPerson.importSocials[0].socialAccount && !regexp.test(this.AddModalData.importPerson.importSocials[0].socialAccount)) {
              this.s_alert("MAC地址格式不正确！正确格式为：XX-XX-XX-XX-XX-XX");
              return;
            }
            else if( this.verifyForm.iphone(this.AddModalData.importPerson.mobile) ){
              this.s_alert("手机号格式不正确！");
              return false;
            }
            else if( this.verifyForm.isNumber(this.AddModalData.importPersonInfo.drivingLicenseNumber) ){
              this.s_alert("行驶证号码格式不正确！");
              return false;
            }
            else if( this.verifyForm.isCarCode(this.AddModalData.importPerson.importVechiles[0].vechileNo) ){
              this.s_alert("车牌号格式不正确！");
              return false;
            }
           /* else if( this.verifyForm.isNumber(this.AddModalData.importPersonInfo.passportNumber) ){
              this.s_alert("护照号不正确！");
              return false;
            }*/
        /*    else if( this.verifyForm.isNull(this.AddModalData.importPersonInfo.nation) ){
              this.s_alert("民族不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.importPersonInfo.spellName) ){
              this.s_alert("拼音不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.importPersonInfo.currentAddress) ){
              this.s_alert("现住址不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.importPerson.ownerGroup) ){
              this.s_alert("所属群体不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.importPersonInfo.personLevel) ){
              this.s_alert("请选择人等级！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.importPersonInfo.personnelStatus) ){
              this.s_alert("请选择人状态！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.stationid) ){
              this.s_alert("管辖分局不能为空！");
              return false;
            }*/

            this.AddModalData.importPerson.id = null;

            this.$axios.put(this.ControlObject+"/BS/ImportPerson/info/"+ this.selectRowId +"?userId=" + this.isLogin().userId,this.AddModalData)
              .then((data)=>{
                //console.log(data);
                this.s_alert("修改成功！");
                this.close();
              })
              .catch((err)=>{
                let errMsg = err.response.data.errorMsg;
                if( errMsg.indexOf('ID_CARD_NO') > 0 ){
                  this.s_alert("身份证已经存在！");
                }else {
                  this.s_alert(errMsg);
                }
              })
          },
          //获取重点人类型结构
          getKeyPersonClassTree(){
            //GET /BS/ImportPersonType/all/{userId}
            this.$axios.get(this.ControlObject + "/BS/ImportPersonType/all/" + this.isLogin().userId )
              .then( res =>{
                //console.log(res);
                let seccessData = res.data;
                let setNewData = [];
                for( let i=0;i<seccessData.length;i++ ){
                  let obj = {};
                  obj.id = seccessData[i].id;
                  obj.name = seccessData[i].typename;
                  obj.pId = seccessData[i].parentid;
                  setNewData.push(obj)
                }
                //console.log(setNewData);
                $.fn.zTree.init($("#RevampKeyPersonClassTree"), this.keyPersonClassTree, setNewData);
              })
              .catch( err =>{
                //console.log(err);
              })
          },

          sexSelect(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPerson.sex = ele.target.value
          },
          selectPersonLevel(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.personLevel = ele.target.value
          },
          selectPersonnelStatus(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.personnelStatus = ele.target.value
          },
          selectIsCriminalRecord(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.isCriminalRecord = ele.target.value
          },
          selectPermanentPopulation(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.permanentPopulation = ele.target.value
          },
          selectTemporaryPopulation(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.temporaryPopulation = ele.target.value
          },
          selectIsDrugUse(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.isDrugUse = ele.target.value
          },
          selectIsViolent(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.isViolent = ele.target.value
          },
          sexUpTypeSelect(ele){
            ////console.log(ele.target.value);
            this.AddModalData.upType = ele.target.value
          },
          isWuhanIdcardSelect(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.isWuhanIdcard = ele.target.value
          },
          //文化程度
          educationLevel(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.educationalLevel = ele.target.value
          },
          //婚姻状况
          selectMaritalStatus(ele){
            ////console.log(ele.target.value);
            this.AddModalData.importPersonInfo.maritalStatus = ele.target.value
          },
          //相片
          filePhoto(ele){
            if( ele.target.files[0].type === "image/png" || ele.target.files[0].type === "image/jpeg" ){
              this.photoFile = ele.target.files[0];
              this.upImgBtn = false;
              this.photoSrc = window.URL.createObjectURL(this.photoFile);
            }else{
              this.s_alert("目前上传格式仅支持png/jpeg！");
            }
          },

          //绑定相片
          bindPhoto(){
            //jp-TIFS-FileCenter-ms/file?businessId=

            let param = new FormData();
            param.append('file',this.photoFile);//通过append向form对象添加数据
            //console.log(this.photoFile);
            let configFile = {
              headers:{'Content-Type':'multipart/form-data'}
            };
            this.$axios.post(baseURL+"api/jp-TIFS-FileCenter-ms/file",param,configFile)
              .then((data)=>{
                this.s_alert("上传成功！");
                //console.log(data.data.fileID);
                this.upImgBtn = true;
                this.AddModalData.importPerson.importPersonImages[0].url = data.data.fileID;
              })
              .catch((err)=>{
                this.s_alert("上传失败！");
                //console.log(err);
              });
          },

          //清除照片
          clearBindPhoto(){
            this.upImgBtn = true;
            this.photoSrc = "";
            this.$refs.formFile.value = "";
            this.AddModalData.importPerson.importPersonImages[0].url = "";
          },

          //展开部门树
          getStationTree(type){
            switch (type){
              case 'sectionTree':
                this.sectionTreeIShow = !this.sectionTreeIShow;
                break;
              case 'sectionPolice':
                this.sectionPoliceTreeIShow = !this.sectionPoliceTreeIShow;
                break;
              case 'sectionData':
                this.sectionDataTreeIShow = !this.sectionDataTreeIShow;
                break;
            }
          },
          getKeyPersonClassTreeIsShow(){
            this.keyPersonClassTreeIShow = !this.keyPersonClassTreeIShow;
          },
          //加载部门树
          getStationTreeAjax(){
            this.$axios.get(this.HOST+'/station/getOrgaInfo')
              .then((data)=>{
                this.sectionTree = data.data.data;
                $.fn.zTree.init($("#RevampSectionTree"), this.sectionTreeSetting, this.sectionTree);
                $.fn.zTree.init($("#RevampSectionPoliceTree"), this.sectionPoliceTreeSetting, this.sectionTree);
                $.fn.zTree.init($("#RevampSectionDataTree"), this.sectionDataTreeSetting, this.sectionTree);
                //console.log(data);
              })
              .catch((err)=>{
                //console.log(err);
              })
          },
          //关闭弹窗
          close(){
            this.$emit("toggleRevampModalFn");
            this.clearData(); //关闭弹窗清除数据
          },
          //录入提示
          upDataTypeTextIsShowFn(){
            this.upDataTypeTextIsShow = !this.upDataTypeTextIsShow;
          },
          //清除数据
          clearData(){
            this.AddModalData={
              "importPerson": {
                "id":null,
                  "birthPlace": "", //birthPlace
                  "idCardNo": "", //身份证号码
                  "reportunit": "",//上报单位
                  "importPersonImages": [ //相片
                  {
                    "url": ""
                  }
                ],
                  "importPersonTypes": [ //重点人类型
                  {
                    "id": "",
                    "typename": ""
                  }
                ],
                  "importSocials": [
                  {
                    "socialAccount": "",//mac地址
                    "type": "mac",
                  }
                ],
                  "importVechiles": [
                  {
                    "vechileNo": "",//车牌号
                  }
                ],
                  "mobile": "", //手机号
                  "name": "", //姓名
                  "ownerGroup": "", //所属群体
                  "sex": "-1",//性别
                  "stationid": "" //管辖所属单位 老字段
              },
              "importPersonInfo": {
                  "birthday": "",//出生日期
                  "criminalRecordDescribe": "",//犯罪记录简述
                  "currentAddress": "",//现住址
                  "drivingLicenseNumber": "", //行驶证号码
                  "educationalLevel": "",//文化程度
                  "exitPermit": "",//港澳通行证
                  "formerName": "",//曾用名
                  "isCriminalRecord": 0,//是否有犯罪记录
                  "isDrugUse": 0,//是否有吸毒史
                  "isViolent": 0,//是否有暴力倾向
                  "isWuhanIdcard": 0, //isWuhanIdcard
                  "maritalStatus": "",//婚姻情况
                  "nation": "",//民族
                  "nativePlace": "",//籍贯
                  "nickname": "",//绰号
                  "passportNumber": "",//护照号
                  "permanentPopulation": "false", //常住人口
                  "personLevel": "-1",//人员等级
                  "personnelStatus": "-1",//人员状态
                  "policestationid": "",//管辖派出所
                  "secondpolicestationid": "",//管辖分局
                  "spellName": "",//姓名拼音
                  "streetAddress": "",//详细住址
                  "temporaryPopulation": "false", //暂住人口
                  "sex": "",//性别
                  "name": "", //姓名
                  "idCardNo": "", //身份证号码
              }
            };
            this.sectionPoliceTreeName = "";
            this.sectionTreeName = "";
            this.sectionDataTreeName = "";
            this.$refs.revampBirthday.value = "";
            this.clearBindPhoto();
          }
        }
    }
</script>

<style scoped>
  .sectionTree{
    position: absolute;
    top: 30px;
    right: 0;
    width: 60%;
    z-index: 2;
    background-color: #fff;
    border:1px solid rgba(51,51,51,0.2);
    box-sizing: border-box;
    padding: 5px;
    max-height: 200px;
    overflow-y: auto;
  }
  .fadeInDown,.fadeOutUp{
    animation-duration: .500s;
  }
  .bounce-enter-active {
    animation: bounce-in 0.555s;
  }

  .bounce-leave-active {
    animation: bounce-in 0.555s reverse;
  }

  @keyframes bounce-in {
    0% {
      transform: scale(0);
    }
    50% {
      transform: scale(1.1);
    }
    100% {
      transform: scale(1);
    }
  }
  .form-control{
    height: 100%;
    border: 1px solid #ccc;
  }
</style>
